package com.gitee.hifong45;

import java.util.HashMap;
import java.util.Map;

import cn.hutool.core.lang.Console;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.map.MapProxy;
import cn.hutool.json.JSONUtil;
import lombok.var;

public class Kv extends Dict {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1094425824273980647L;
	
	public static void main(String[] args) {
		Dict dict = Dict.of(
			 	"RED", "#FF0000",
			 	"GREEN", "#00FF00",
			 	"BLUE", "#0000FF"
			 );
		Console.log(dict); // 输出 {null=RED, #FF0000=GREEN, #00FF00=BLUE}
	}
	
	public static Kv of() {
		return new Kv();
	}
	
	public static MapProxy of(Map<?, ?> _map) {
		return MapProxy.create(_map);
	}

	public static Kv of(Object... input) {
		if ((input.length & 1) != 0) { // implicit nullcheck of input
			throw new InternalError("length is odd");
		}

		var _m = new Kv();
		for (int i = 0; i < input.length; i += 2) {
			String k = (String) input[i];
			Object v = input[i + 1];
			_m.put(k, v);
		}
		return _m;
	}
	
	public static Map<String, String> ofStr(String... input) {
		if ((input.length & 1) != 0) { // implicit nullcheck of input
			throw new InternalError("length is odd");
		}
		
		var _m = new HashMap<String, String>();
		for (int i = 0; i < input.length; i += 2) {
			String k = input[i];
			String v = input[i + 1];
			_m.put(k, v);
		}
		return _m;
	}

	@Override
	public String toString() {
		return JSONUtil.toJsonStr(this);
	}
}
